package com.qyhl.module_home.home.fuquan;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.gyf.immersionbar.ImmersionBar;
import com.luck.picture.lib.tools.ScreenUtils;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qyhl.module_home.R;
import com.qyhl.module_home.R2;
import com.qyhl.module_home.common.HomeUrl;
import com.qyhl.webtv.basiclib.base.BaseFragment;
import com.qyhl.webtv.basiclib.utils.StringUtils;
import com.qyhl.webtv.basiclib.utils.ToastUtils;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.constant.AppConfigConstant;
import com.qyhl.webtv.commonlib.entity.act.ActDetailsBean;
import com.qyhl.webtv.commonlib.entity.broke.ScoopTopicBean;
import com.qyhl.webtv.commonlib.entity.circle.CircleHomeBean;
import com.qyhl.webtv.commonlib.entity.circle.ScoopListBean;
import com.qyhl.webtv.commonlib.entity.config.AppConfigBean;
import com.qyhl.webtv.commonlib.entity.home.GatherBean;
import com.qyhl.webtv.commonlib.entity.home.HomeBean;
import com.qyhl.webtv.commonlib.entity.home.NewsBean;
import com.qyhl.webtv.commonlib.entity.live.ShoppingListBean;
import com.qyhl.webtv.commonlib.entity.live.TeleTextBean;
import com.qyhl.webtv.commonlib.entity.news.AdvHomeBean;
import com.qyhl.webtv.commonlib.entity.news.AdvertiseBean;
import com.qyhl.webtv.commonlib.entity.news.GlobalNewsBean;
import com.qyhl.webtv.commonlib.entity.news.UnionBean;
import com.qyhl.webtv.commonlib.entity.user.MessageUnreadBean;
import com.qyhl.webtv.commonlib.item.ItemGoodLife;
import com.qyhl.webtv.commonlib.item.ItemScoopTopic;
import com.qyhl.webtv.commonlib.item.ItemSmallVideo;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanAct;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanAdvCommon;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanAdvGroup;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanAdvLarge;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanCirclePic;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanCircleText;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanCircleTopic;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanCircleVideo;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanLive;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanNews;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanNewsLarge;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanNoPic;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanPic;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanScoop;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanShop;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanTop;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanUnion;
import com.qyhl.webtv.commonlib.item.fuquan.ItemFuQuanUnionLarge;
import com.qyhl.webtv.commonlib.service.UserService;
import com.qyhl.webtv.commonlib.utils.ItemSkipUtils;
import com.qyhl.webtv.commonlib.utils.PageGridView;
import com.qyhl.webtv.commonlib.utils.ResizableImageView;
import com.qyhl.webtv.commonlib.utils.action.ActionConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionLogUtils;
import com.qyhl.webtv.commonlib.utils.cache.SpfManager;
import com.qyhl.webtv.commonlib.utils.config.AppConfigUtil;
import com.qyhl.webtv.commonlib.utils.router.RouterManager;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.stx.xhb.androidx.XBanner;
import com.stx.xhb.androidx.transformers.Transformer;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.analytics.MobclickAgent;
import com.weavey.loading.lib.LoadingLayout;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.adapter.recyclerview.wrapper.HeaderAndFooterWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import butterknife.BindView;
import butterknife.OnClick;
import es.dmoral.toasty.Toasty;
import q.rorbin.badgeview.QBadgeView;

@SuppressLint("NonConstantResourceId")
public class FuQuanHomeFragment extends BaseFragment implements FuQuanHomeContract.FuQuanHomeView {
    @BindView(R2.id.title_img)
    ResizableImageView titleImg;
    @BindView(R2.id.title_logo)
    ResizableImageView titleLogo;
    @BindView(R2.id.message_btn)
    TextView messageBtn;
    @BindView(R2.id.recycle_view)
    RecyclerView recycleView;
    @BindView(R2.id.refresh)
    SmartRefreshLayout refresh;
    @BindView(R2.id.load_mask)
    LoadingLayout loadMask;

    private FuQuanHomePresenter mPresenter;

    private PageGridView pageGridView;

    private LinearLayout recommendLayout;

    private List<HomeBean.SecMenus> pageList;

    private RecyclerView topMenu, recommendRecycler, centerMenu;

    private MultiItemTypeAdapter<GlobalNewsBean> mAdapter;

    private XBanner xBanner, advBanner;

    private List<HomeBean.TopNews> bannerList;

    private List<AppConfigBean.ThreeMenus> threeMenus;

    private List<HomeBean.SecMenus> topList;

    private CommonAdapter<NewsBean> recommendAdapter;

    private List<NewsBean> recommendList = new ArrayList<>();

    private CommonAdapter<AppConfigBean.ThreeMenus> topAdapter;

    private HeaderAndFooterWrapper<GlobalNewsBean> headerAndFooterWrapper;

    private List<GlobalNewsBean> mDataList = new ArrayList<>();

    private List<HomeBean.SecMenus> cTabMenuList;

    private CommonAdapter<HomeBean.SecMenus> cMenuAdapter;

    private int todayRec;

    private String appLogo;

    private String appTitle;

    private int page = 1;

    private String lastType = "0";

    private int lastNewsId = 0;//记录请求最后一条id,加载时从该id后查询

    private QBadgeView badgeView;

    public void setAppTitle(String appTitle) {
        this.appTitle = appTitle;
    }

    public void setTabMenuList(List<HomeBean.SecMenus> cTabMenuList) {
        this.cTabMenuList = cTabMenuList;
    }

    public void setTodayRec(int todayRec) {
        this.todayRec = todayRec;
    }

    private void setThreeMenus(List<AppConfigBean.ThreeMenus> threeMenus) {
        this.threeMenus = threeMenus;
    }

    public void setAppLogo(String appLogo) {
        this.appLogo = appLogo;
    }

    public static FuQuanHomeFragment newInstance(List<AppConfigBean.ThreeMenus> threeMenus, List<HomeBean.SecMenus> tabList, int todayRec, String appTitle,String appLogo) {
        FuQuanHomeFragment homeFragment = new FuQuanHomeFragment();
        homeFragment.setThreeMenus(threeMenus);
        homeFragment.setTabMenuList(tabList);
        homeFragment.setTodayRec(todayRec);
        homeFragment.setAppLogo(appLogo);
        homeFragment.setAppTitle(appTitle);
        return homeFragment;
    }

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.home_fragment_home_fuquan, null);
    }

    @Override
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(FuQuanHomeFragment.this)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void onFirstVisible() {

    }

    @Override
    protected void onVisible() {

    }

    @Override
    protected void onHide() {

    }

    @Override
    protected void create() {
        Glide.with(FuQuanHomeFragment.this)
                .load(appTitle)
                .apply(new RequestOptions().error(R.drawable.title_panzhou).error(R.drawable.title_panzhou))
                .into(titleImg);

        Glide.with(FuQuanHomeFragment.this)
                .load(appLogo)
                .apply(new RequestOptions().error(R.mipmap.ic_launcher_round).error(R.mipmap.ic_launcher_round))
                .into(titleLogo);

        loadMask.setStatus(LoadingLayout.Loading);
        topList = new ArrayList<>();
        for (int i = 0; i < threeMenus.size(); i++) {
            topList.add(new HomeBean.SecMenus(threeMenus.get(i).getStyleId(), threeMenus.get(i).getSecondId(), threeMenus.get(i).getSiteId()
                    , threeMenus.get(i).getMenuImg(), threeMenus.get(i).getTypeId(), threeMenus.get(i).getUrl(), threeMenus.get(i).getMenuName()));
        }

        mPresenter = new FuQuanHomePresenter(this);

        refresh.setRefreshHeader(new MaterialHeader(getContext()));
        refresh.setRefreshFooter(new ClassicsFooter(getContext()));
        refresh.setEnableLoadMore(true);

        recycleView.setLayoutManager(new LinearLayoutManager(getContext()));

        DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(Objects.requireNonNull(ContextCompat.getDrawable(getContext(), R.drawable.home_fuquan_divider)));
        recycleView.addItemDecoration(divider);

        View headView = LayoutInflater.from(getContext()).inflate(R.layout.home_fragment_header_fuquan, null);
        topMenu = headView.findViewById(R.id.top_menu);
        xBanner = headView.findViewById(R.id.banner);
        pageGridView = headView.findViewById(R.id.page_view);
        advBanner = headView.findViewById(R.id.adv_banner);
        recommendRecycler = headView.findViewById(R.id.recommend_recycler);
        centerMenu = headView.findViewById(R.id.center_menu);
        recommendLayout = headView.findViewById(R.id.recommend_layout);

        topMenu.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
        topMenu.setAdapter(topAdapter = new CommonAdapter<AppConfigBean.ThreeMenus>(getContext(), R.layout.home_item_fuquan_top_menu, threeMenus) {
            @Override
            protected void convert(ViewHolder holder, AppConfigBean.ThreeMenus bean, int position) {
                ImageView cover = holder.getView(R.id.cover);
                RelativeLayout layout = holder.getView(R.id.mask_layout);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) layout.getLayoutParams();

                int width = ScreenUtils.getScreenWidth(getContext()) / 4;
                params.width = width;
                layout.setLayoutParams(params);

                Glide.with(FuQuanHomeFragment.this)
                        .load(bean.getMenuImg())
                        .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                        .into(cover);

                holder.setText(R.id.title, bean.getMenuName());
            }
        });

        if (cTabMenuList != null && cTabMenuList.size() > 0) {
            centerMenu.setVisibility(View.VISIBLE);
            centerMenu.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));

            centerMenu.setAdapter(cMenuAdapter = new CommonAdapter<HomeBean.SecMenus>(getContext(), R.layout.home_item_fuquan_center_menu, cTabMenuList) {
                @Override
                protected void convert(ViewHolder holder, HomeBean.SecMenus secMenus, int position) {
                    ImageView cover = holder.getView(R.id.cover);
                    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) cover.getLayoutParams();

                    int width = (ScreenUtils.getScreenWidth(getContext()) - StringUtils.dip2px(getContext(), 35)) / 2;
                    params.width = width;
                    params.height = width * 7 / 17;


                    cover.setLayoutParams(params);

                    Glide.with(FuQuanHomeFragment.this)
                            .load(secMenus.getMenuImg())
                            .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                            .into(cover);
                }
            });

            cMenuAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                    navigationSkip(cTabMenuList.get(i));
                }

                @Override
                public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                    return false;
                }
            });

        } else {
            centerMenu.setVisibility(View.GONE);
        }

        recommendRecycler.setLayoutManager(new LinearLayoutManager(getContext()));
        recommendRecycler.setAdapter(recommendAdapter = new CommonAdapter<NewsBean>(getContext(), R.layout.home_item_fuquan_recommend, recommendList) {
            @Override
            protected void convert(ViewHolder holder, NewsBean bean, int position) {
                if (position == recommendList.size() - 1) {
                    holder.setVisible(R.id.divider, false);
                } else {
                    holder.setVisible(R.id.divider, true);
                }

                RoundedImageView cover = holder.getView(R.id.cover);

                Glide.with(FuQuanHomeFragment.this)
                        .load(bean.getLogo())
                        .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                        .into(cover);

                holder.setText(R.id.title, bean.getTitle());

                //来源
                TextView origin = holder.getView(R.id.origin);
                if (StringUtils.isNotEmpty(bean.getCatalogName())) {
                    origin.setVisibility(View.VISIBLE);
                    origin.setText(bean.getCatalogName());
                } else {
                    origin.setVisibility(View.GONE);
                }

                //阅读数
                TextView scan = holder.getView(R.id.scan);
                try {
                    int minPlay = Integer.parseInt(CommonUtils.getInstance().getMinPlay());
                    if (minPlay == 0) {
                        scan.setVisibility(View.GONE);
                    } else {
                        //判断评论数是否大于最少浏览数
                        if (StringUtils.isEmpty(bean.getHitCount())) {
                            scan.setVisibility(View.GONE);
                        } else if (Integer.parseInt(bean.getHitCount()) >=
                                minPlay) {
                            scan.setText(StringUtils.transformNum(bean.getHitCount()) + "阅");
                            scan.setVisibility(View.VISIBLE);
                        } else {
                            scan.setVisibility(View.GONE);
                        }
                    }

                } catch (Exception e) {
                    scan.setVisibility(View.GONE);
                }
            }
        });


        mAdapter = new MultiItemTypeAdapter<>(getContext(), mDataList);

        mAdapter.addItemViewDelegate(new ItemFuQuanCircleTopic(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanNews(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanNewsLarge(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanPic(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanAct(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanLive(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanCircleTopic(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanNoPic());
        mAdapter.addItemViewDelegate(new ItemFuQuanScoop());
        mAdapter.addItemViewDelegate(new ItemFuQuanUnion(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanTop(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanUnionLarge(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanAdvCommon(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanAdvGroup(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanAdvLarge(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanCircleText());
        mAdapter.addItemViewDelegate(new ItemFuQuanCirclePic(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanCircleVideo(getContext()));
        mAdapter.addItemViewDelegate(new ItemGoodLife(getContext()));
        mAdapter.addItemViewDelegate(new ItemSmallVideo(getContext()));
        mAdapter.addItemViewDelegate(new ItemFuQuanShop(getContext()));
        mAdapter.addItemViewDelegate(new ItemScoopTopic());

        headerAndFooterWrapper = new HeaderAndFooterWrapper<>(mAdapter);
        headerAndFooterWrapper.addHeaderView(headView);
        recycleView.setAdapter(headerAndFooterWrapper);

        mPresenter.getConfig();
        mPresenter.getAdvData();
        mPresenter.getGatherData(page, lastNewsId, lastType);
        if (todayRec != 0) {
            recommendLayout.setVisibility(View.VISIBLE);
            mPresenter.getTodayRec(todayRec);
        } else {
            recommendLayout.setVisibility(View.GONE);
        }
    }

    @Override
    protected void setListener() {
        topAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                navigationSkip(topList.get(i));
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }
        });

        pageGridView.setOnItemClickListener(new PageGridView.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                navigationSkip(pageList.get(position));
            }
        });

        //重新加载
        loadMask.setOnReloadListener(new LoadingLayout.OnReloadListener() {
            @Override
            public void onReload(View v) {
                loadMask.setReloadButtonText("加载中...");
                page = 1;
                lastNewsId = 0;
                lastType = "0";
                mPresenter.getConfig();
                mPresenter.getAdvData();
                mPresenter.getGatherData(page, lastNewsId, lastType);
                if (todayRec != 0) {
                    mPresenter.getTodayRec(todayRec);
                }
            }
        });
        //刷新
        refresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                page = 1;
                lastNewsId = 0;
                lastType = "0";
                mPresenter.getConfig();
                mPresenter.getAdvData();
                mPresenter.getGatherData(page, lastNewsId, lastType);
                if (todayRec != 0) {
                    mPresenter.getTodayRec(todayRec);
                }
            }
        });

        //加载更多
        refresh.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                page++;
                mPresenter.getGatherData(page, lastNewsId, lastType);
            }
        });

        mAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int position) {
                GlobalNewsBean bean = null;
                if (position >= 0) {
                    if (recycleView.getAdapter().getItemCount() == mDataList.size()) {
                        bean = mDataList.get(position);
                    } else {
                        if (position != 0) {
                            bean = mDataList.get(position - 1);
                        }
                    }
                }
                ItemSkipUtils.getInstance().itemSkip(bean, getContext(), view);
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }
        });

        recommendAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int position) {
                NewsBean bean = recommendList.get(position);
                switch (recommendList.get(position).getType()) {
                    case "1"://普通新闻
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", bean.getID());
                        RouterManager.router(ARouterPathConstant.NORMAL_NEWS_ACTIVITY, bundle);
                    }
                    break;
                    case "2"://图片新闻
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", bean.getID());
                        bundle.putString("section", bean.getCatalogID());
                        RouterManager.router(ARouterPathConstant.PICTURE_NEWS_ACTIVITY, bundle);
                    }

                    break;
                    case "3"://直播
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("newsId", bean.getID());
                        bundle.putString("liveType", bean.getLivetype());
                        RouterManager.router(ARouterPathConstant.LIVE_NORMAL_ACTIVITY, bundle);
                    }
                    break;
                    case "4"://标题新闻
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", bean.getID());
                        bundle.putString("title", bean.getTitle());
                        bundle.putString("url", bean.getRedirectURL());
                        RouterManager.router(ARouterPathConstant.ADV, bundle);
                    }
                    break;
                    case "5"://视频新闻
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", bean.getID());
                        RouterManager.router(ARouterPathConstant.VIDEO_NEWS_ACTIVITY, bundle);
                    }
                    break;
                    case "8"://互动直播
                        break;
                    case "101"://抓取新闻
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("id", bean.getID());
                        RouterManager.router(ARouterPathConstant.NEWS_CATCH, bundle);
                    }
                    break;
                    default:
                        break;

                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }
        });
    }

    @OnClick({R2.id.message_btn, R2.id.search_btn})
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.message_btn) {
            CommonUtils.getInstance().isLogin(new UserService.LoginCallBack() {
                @Override
                public void login(boolean isLogin) {
                    if (isLogin) {
                        RouterManager.router(ARouterPathConstant.NEW_MESSAGE);
                    } else {
                        RouterManager.routerLogin(getActivity(), 0);
                    }
                }

                @Override
                public void error(String s) {

                }
            });
        } else if (viewId == R.id.search_btn) {
            RouterManager.router(ARouterPathConstant.SEARCH);
            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.SEARCH);
        }
    }

    @Override
    public void setBanner(boolean isShow, List<HomeBean.TopNews> list) {
        int bannerNum = CommonUtils.getInstance().getBannerNum();
        if (isShow && bannerNum != 0) {
            bannerList = new ArrayList<>();
            if (list.size() <= bannerNum) {
                bannerList = list;
            } else {
                for (int i = 0; i < bannerNum; i++) {
                    bannerList.add(list.get(i));
                }
            }
            xBanner.setVisibility(View.VISIBLE);

            xBanner.setPageTransformer(Transformer.Default);
            xBanner.setBannerData(R.layout.home_item_top_banner_fuquan, bannerList);
            xBanner.loadImage(new XBanner.XBannerAdapter() {
                @Override
                public void loadBanner(XBanner banner, Object model, View view, int position) {
                    TextView titleTv = view.findViewById(R.id.title);
                    titleTv.setText(((HomeBean.TopNews) model).getArticleTitle());

                    RoundedImageView bannerCover = view.findViewById(R.id.cover);
                    Glide.with(FuQuanHomeFragment.this)
                            .load(((HomeBean.TopNews) model).getArticleImg())
                            .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                            .into(bannerCover);


                }
            });

            xBanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
                @Override
                public void onItemClick(XBanner banner, Object model, View view, int position) {
                    HomeBean.TopNews bean = bannerList.get(position);
                    String type = null;
                    switch (bean.getType()) {
                        //活动
                        case "0":
                            if ("1".equals(bean.getActivityJson().getType())) {
                                type = "11";
                            } else {
                                type = "12";
                            }
                            break;
                        //普通
                        case "1":
                            type = "1";
                            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOPNEWS);
                            break;
                        //图片
                        case "2":
                            type = "2";
                            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOPNEWS);
                            break;
                        //直播
                        case "3":
                            type = "9";
                            break;
                        //标题
                        case "4":
                            type = "8";
                            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOPNEWS);
                            break;
                        //视频
                        case "5":
                            type = "3";
                            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOPNEWS);
                            break;
                        case "101"://抓取新闻
                            type = "10";
                            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOPRECOMMENDNEWS);
                            break;
                        case "102"://小视频
                            type = "7";
                            break;
                        default:
                            break;

                    }
                    GlobalNewsBean globalNewsBean = new GlobalNewsBean(bean.getArticleTitle(), bean.getArticleID(), bean.getArticleURL(), bean.getArticleImg(), 0, null, bean.getType(), 0, null, bean.getCatalogID(), false, type, bean.getLivetype());
                    ItemSkipUtils.getInstance().itemTopSkip(globalNewsBean, getContext());
                }
            });

        } else {
            xBanner.setVisibility(View.GONE);
        }
    }

    @Override
    public void setAdvBanner(boolean isShow, List<AdvHomeBean> list) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        boolean isFinallyShow = false;
        if (isShow) {
            advBanner.setVisibility(View.VISIBLE);
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getPosition().equals("2")) {//中
                    if (list.get(i).getAdvertise() != null && list.get(i).getAdvertise().size() > 0) {
                        isFinallyShow = true;
                        advBanner.setBannerData(list.get(i).getAdvertise());

                        advBanner.loadImage(new XBanner.XBannerAdapter() {
                            @Override
                            public void loadBanner(XBanner banner, Object model, View view, int position) {
                                Glide.with(FuQuanHomeFragment.this)
                                        .load(((AdvertiseBean) model).getImageUrl())
                                        .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                                        .into((ImageView) view);
                            }
                        });

                        int finalI = i;
                        advBanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
                            @Override
                            public void onItemClick(XBanner banner, Object model, View view, int position) {
                                advSkip(list.get(finalI).getAdvertise().get(position));
                            }
                        });
                    }
                }
            }
        } else {
            advBanner.setVisibility(View.GONE);
        }

        if (isFinallyShow) {
            advBanner.setVisibility(View.VISIBLE);
        } else {
            advBanner.setVisibility(View.GONE);
        }
    }

    @Override
    public void setGatherNews(List<GatherBean> beanList, boolean isMore) {
        loadMask.setStatus(LoadingLayout.Success);
        loadMask.setReloadButtonText("点击重试~~");

        if (isMore) {
            refresh.finishLoadMore();
        } else {
            mDataList.clear();
            refresh.finishRefresh();
        }

        mDataList.addAll(dataTranslate(beanList));
        headerAndFooterWrapper.notifyDataSetChanged();

        page++;
        try {  //获取最后一条新闻的id
            lastType = beanList.get(beanList.size() - 1).getType();
            switch (beanList.get(beanList.size() - 1).getType()) {
                case "5":
                    lastNewsId = beanList.get(beanList.size() - 1).getAdv().getId();
                    break;
                case "6":
                case "8":
                case "7":
                    lastNewsId = Integer.parseInt(beanList.get(beanList.size() - 1).getCatalog().getInnercode());
                    break;
                case "9":
                    lastNewsId = beanList.get(beanList.size() - 1).getLiveNews().getId();
                    break;
                case "10":
                    lastNewsId = beanList.get(beanList.size() - 1).getTopicInfo().getId();
                    break;
                case "11":
                    lastNewsId = beanList.get(beanList.size() - 1).getCircleTag().getId();
                    break;
                case "12":
                    lastNewsId = beanList.get(beanList.size() - 1).getBrokeNewsPlate().getId();
                    break;
                case "13":
                    lastNewsId = beanList.get(beanList.size() - 1).getBrokeNews().getBrokeNews().getId();
                    break;
                default:
                    lastNewsId = Integer.parseInt(beanList.get(beanList.size() - 1).getNews().getID());
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    @Override
    public void showError(String msg) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        showToast(msg);
        loadMask.setStatus(LoadingLayout.Error);
        loadMask.setReloadButtonText("点击重试~~");
    }

    @Override
    public void showMessage(String msg) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        if (page > 1) {
            page--;
        }
        Toasty.normal(getContext(), msg, Toast.LENGTH_SHORT).show();//显示信息
    }

    @Override
    public void showEmpty(String s) {
        refresh.finishRefresh();
        refresh.finishLoadMore();
        loadMask.setStatus(LoadingLayout.Success);
        loadMask.setReloadButtonText("点击重试~~");
    }

    @Override
    public void setNavigation(boolean isShow, List<HomeBean.SecMenus> list) {
        pageList = list;
        if (isShow) {
            pageGridView.setVisibility(View.VISIBLE);

            List<MyIconModel> mList = new ArrayList<>();
            for (int i = 0; i < list.size(); i++) {
                mList.add(new MyIconModel(list.get(i).getMenuName(), getContext(), list.get(i).getMenuImg()));
            }

            if (mList.size() <= 5) {
                pageGridView.setPageSize(5);
            } else {
                pageGridView.setPageSize(10);
            }

            pageGridView.setData(mList);

        } else {
            pageGridView.setVisibility(View.GONE);
        }
    }

    @Override
    public void setTopShop(List<ShoppingListBean> bean) {

    }

    @Override
    public void setTodayRec(List<NewsBean> beanList) {
        recommendList.clear();
        if (beanList != null) {
            recommendLayout.setVisibility(View.VISIBLE);
            if (beanList.size() > 3) {
                List<NewsBean> list = new ArrayList<>();
                for (int i = 0; i < 3; i++) {
                    list.add(beanList.get(i));
                }
                recommendList.addAll(list);
            } else {
                recommendList.addAll(beanList);
            }

            recommendAdapter.notifyDataSetChanged();
        } else {
            recommendLayout.setVisibility(View.GONE);
        }
    }


    @Override
    public void onResume() {
        super.onResume();
        EasyHttp.get(HomeUrl.GET_UNREAD_MSG_NUM)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("devType", "Android")
                .params("sTime", SpfManager.getInstance(getContext()).getString("last_system_time", "0"))
                .params("tTime", SpfManager.getInstance(getContext()).getString("last_tip_time", "0"))
                .params("userName", CommonUtils.getInstance().getUserName())
                .execute(new SimpleCallBack<MessageUnreadBean>() {
                    @Override
                    public void onError(ApiException e) {

                    }

                    @Override
                    public void onSuccess(MessageUnreadBean messageUnreadBean) {
                        CommonUtils.getInstance().isLogin(new UserService.LoginCallBack() {
                            @Override
                            public void login(boolean isLogin) {
                                if (isLogin) {
                                    if (messageUnreadBean.getuInteractive() > 0 || messageUnreadBean.getuTips() > 0 || messageUnreadBean.getuSystem() > 0) {
                                        if (badgeView == null) {
                                            badgeView = new QBadgeView(getContext());
                                        }
                                        badgeView.bindTarget(messageBtn).setBadgeNumber(messageUnreadBean.getuSystem() + messageUnreadBean.getuTips() + messageUnreadBean.getuInteractive());
                                    } else {
                                        if (badgeView != null) {
                                            badgeView.hide(false);
                                        }
                                    }
                                } else {
                                    if (badgeView != null) {
                                        badgeView.hide(false);
                                    }
                                }
                            }

                            @Override
                            public void error(String s) {

                            }
                        });
                    }
                });


        //baidu
        //umeng
        MobclickAgent.onPageStart("首页");
        MobclickAgent.onResume(getContext());
        GSYVideoManager.onResume();
    }

    private void navigationSkip(HomeBean.SecMenus bean) {
        switch (bean.getTypeId()) {
            case 1:
                if (bean.getStyleId() == 1) {//资讯样式
                    Bundle bundle = new Bundle();
                    bundle.putString("title", bean.getMenuName());
                    bundle.putString("id", bean.getSecondId() + "");
                    bundle.putString("type", "-1");
                    RouterManager.router(ARouterPathConstant.INFO, bundle);
                } else { //节目样式
                    Bundle bundle = new Bundle();
                    bundle.putString("title", bean.getMenuName());
                    bundle.putString("menuId", bean.getSecondId() + "");
                    bundle.putString("type", "-1");
                    RouterManager.router(ARouterPathConstant.PROGRAM, bundle);
                    ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.INFORMATION);
                }
                break;
            case 2://活动列表
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.ACTIVITY_LIST_TEMP, bundle);
            }
            break;
            case 3://直播列表
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.LIVELIST, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.LIVELIST);
            }
            break;
            case 4://链接
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", "");
                int hasShare = (int) AppConfigUtil.getInstance().getConValue(AppConfigConstant.LINK_URL_SHARE);
                bundle.putBoolean("hasShare", hasShare != 1);

                bundle.putString("url", bean.getUrl());
                bundle.putBoolean("hasJS", true);
                RouterManager.router(ARouterPathConstant.ADV, bundle);
            }
            break;
            case 5://电商
                break;
            case 6://新闻列表
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                if (bean.getStyleId() == 5) {
                    bundle.putString("catalogId", bean.getUrl());
                    bundle.putInt("type", 6);
                    RouterManager.router(ARouterPathConstant.NB_LIST, bundle);
                } else {
                    bundle.putString("id", bean.getUrl());
                    if (bean.getMenuName().equals("求职招聘")) {
                        bundle.putBoolean("hasSearch", true);
                    }
                    RouterManager.router(ARouterPathConstant.NEWS_LIST, bundle);
                }
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.SECTIONS);
            }
            break;
            case 7://新趣汇
            {
                RouterManager.router(ARouterPathConstant.GOOD_LIFE);
            }
            ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.GOODLIFE);
            break;
            case 8://小视频
            {
                RouterManager.router(ARouterPathConstant.SMALLVIDEO);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.SMALLVIDEO);
            }
            break;
            case 9:
                switch (bean.getStyleId()) {
                    case 1://乡镇
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("title", bean.getMenuName());
                        bundle.putString("sectionId", bean.getUrl());
                        RouterManager.router(ARouterPathConstant.TOWN_LIST, bundle);
                        ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOWNDETAIL);
                    }
                    break;
                    case 2://政务
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("title", bean.getMenuName());
                        bundle.putString("sectionId", bean.getUrl());
                        RouterManager.router(ARouterPathConstant.GOV_LIST, bundle);
                        ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.GOVDETAIL);
                    }
                    break;
                    case 3://专题
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("title", bean.getMenuName());
                        bundle.putString("sectionId", bean.getUrl());
                        if (bean.getMenuName().equals("乡村振兴")) {
                            bundle.putBoolean("hasSearch", true);
                        }
                        RouterManager.router(ARouterPathConstant.SPECIAL, bundle);
                        ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.SPECIADETAIL);
                    }
                    break;
                    case 4://富顺乡镇样式
                    {
                        Bundle bundle = new Bundle();
                        bundle.putString("title", bean.getMenuName());
                        bundle.putString("sectionId", bean.getUrl());
                        RouterManager.router(ARouterPathConstant.UNION_TOWN3, bundle);
                        ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOWNDETAIL);
                    }
                    break;
                    default:
                        Toasty.normal(getContext(), "类型出错！", Toast.LENGTH_SHORT).show();
                        break;
                }
                break;
            case 10://图文直播
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.TELETEXT_LIST, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TELETEXTLIST);
            }
            break;
            case 11://电视直播  1.广播 2.电视
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", bean.getUrl());
                bundle.putString("type", bean.getStyleId() + "");
                RouterManager.router(ARouterPathConstant.NEWLIVE_LIST, bundle);
            }
            break;
            case 12://传统直播混合列表
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", "");
                RouterManager.router(ARouterPathConstant.MIX_LIVE, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.MIXLIVE);
            }
            break;
            case 13:  //传统直播音频列表
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", "2");
                RouterManager.router(ARouterPathConstant.MIX_LIVE, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.MIXLIVE);
            }
            break;
            case 14: //传统直播视频列表
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", "1");
                RouterManager.router(ARouterPathConstant.MIX_LIVE, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.MIXLIVE);
            }
            break;
            case 15://新乡镇样式
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", bean.getUrl());
                RouterManager.router(ARouterPathConstant.UNION_TOWN2, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.TOWNDETAIL);
            }
            break;
            case 16://新活动
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.ACTIVITY_LIST_TEMP, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.ACTIVITY_LIST);
            }
            break;
            case 17://开票有喜
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", bean.getSecondId() + "");
                RouterManager.router(ARouterPathConstant.LUCK_DRAW, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.LUCK_DRA_HOME);
            }
            break;
            case 18://城事
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.CITY, bundle);
            }
            break;
            case 19://问答
            {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.SCOOP_HOME, bundle);
            }
            break;
            case 20: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.COUPON_HOME_ACTIVITY, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.COUPON_HOME);
            }
            break;
            case 21://百事通
                RouterManager.router(ARouterPathConstant.BESTONE_TYPE);
                break;
            case 22: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.NEWLIVE_LIST, bundle);
            }
            break;
            case 23: {//城阳资讯+ 报料
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("type", "-1");
                bundle.putString("id", bean.getSecondId() + "");
                RouterManager.router(ARouterPathConstant.INFO, bundle);
            }
            break;
            case 24: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putInt("type", 0);
                RouterManager.router(ARouterPathConstant.JL_LIST, bundle);
            }
            break;
            case 25: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putInt("type", 1);
                RouterManager.router(ARouterPathConstant.JL_LIST, bundle);
            }
            break;
            case 26: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.JL_MULTI_LIST, bundle);
            }
            break;
            case 29:
            case 37: {
                Bundle bundle = new Bundle();
                bundle.putString("id", bean.getUrl());
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.PRACTICE_HOME, bundle);
            }
            break;
            case 45:
                RouterManager.router(ARouterPathConstant.QUESTION_HOME);
                break;
            case 49: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.SHOP_LIST, bundle);
            }
            break;
            case 52: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("menuId", bean.getSecondId() + "");
                bundle.putString("type", "-1");
                bundle.putBoolean("hasNew", false);
                RouterManager.router(ARouterPathConstant.NB_LIST, bundle);
                ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.INFORMATION);
            }
            break;
            case 53: {
                RouterManager.router(ARouterPathConstant.SCHOOL_HOME);
            }
            break;
            case 55: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.NANBU_LIVE, bundle);
            }
            break;
            case 56: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                bundle.putString("id", bean.getUrl());
                RouterManager.router(ARouterPathConstant.CLASSIC_DETAIL_NEW, bundle);
            }
            break;
            case 57: {
                String appId = CommonUtils.getInstance().getSHARE_WEIXIN_APPID(); // 填移动应用(App)的 AppId，非小程序的 AppID
                IWXAPI api = WXAPIFactory.createWXAPI(getContext(), appId);

                WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
                req.userName = "gh_c5e311f36f6f"; // 填小程序原始id
                req.path = bean.getUrl();
                ////拉起小程序页面的可带参路径，不填默认拉起小程序首页，对于小游戏，可以只传入 query 部分，来实现传参效果，如：传入 "?foo=bar"。
                req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版，体验版和正式版
                api.sendReq(req);
            }
            break;
            case 59: {
                ARouter.getInstance()
                        .build(ARouterPathConstant.SHOP_HOME)
                        .withString("title", bean.getMenuName())
                        .navigation();
            }
            break;
            case 63: {
                boolean b = checkAppInstalled(getActivity(), "com.ss.android.ugc.aweme");
                if (b) {
                    Intent intent = new Intent();
                    intent.setData(Uri.parse("snssdk1128://user/profile/" + bean.getUrl()));
                    startActivity(intent);
                } else {
                    ToastUtils.showToast(getActivity(), "未安装此应用");
                }
            }
            break;
            default: {
                Bundle bundle = new Bundle();
                bundle.putString("title", bean.getMenuName());
                RouterManager.router(ARouterPathConstant.ACTIVITY_DEFAULT, bundle);
            }
            break;
        }
    }

    private boolean checkAppInstalled(Context context, String pkgName) {
        if (pkgName == null || pkgName.isEmpty()) {
            return false;
        }
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> info = packageManager.getInstalledPackages(0);
        if (info == null || info.isEmpty())
            return false;
        for (int i = 0; i < info.size(); i++) {
            if (pkgName.equals(info.get(i).packageName)) {
                return true;
            }
        }
        return false;
    }

    private void advSkip(AdvertiseBean advertiseBean) {
        if (StringUtils.isEmpty(advertiseBean.getLink())) {
            switch (advertiseBean.getLinkType()) {
                case "1": {
                    Bundle bundle = new Bundle();
                    bundle.putString("id", advertiseBean.getLinkId());
                    RouterManager.router(ARouterPathConstant.TELE_VIDEO_ACTIVITY, bundle);
                }
                break;
                case "2": {
                    Bundle bundle = new Bundle();
                    bundle.putString("id", advertiseBean.getLinkId());
                    RouterManager.router(ARouterPathConstant.SCOOP_DETAIL_ACTIVIT, bundle);
                }
                break;
                case "3":
                    switch (advertiseBean.getContentType()) {
                        case "1": {
                            Bundle bundle = new Bundle();
                            bundle.putString("id", advertiseBean.getLinkId());
                            RouterManager.router(ARouterPathConstant.NORMAL_NEWS_ACTIVITY, bundle);
                        }
                        break;
                        case "2": {
                            Bundle bundle = new Bundle();
                            bundle.putString("id", advertiseBean.getLinkId());
                            bundle.putString("section", advertiseBean.getCatalogID());
                            RouterManager.router(ARouterPathConstant.PICTURE_NEWS_ACTIVITY, bundle);
                        }
                        break;
                        case "3":
                            break;
                        case "4":
                            break;
                        case "5": {
                            Bundle bundle = new Bundle();
                            bundle.putString("id", advertiseBean.getLinkId());
                            RouterManager.router(ARouterPathConstant.VIDEO_NEWS_ACTIVITY, bundle);
                        }
                        break;
                        case "8": {
                        }
                        break;
                        case "101": {
                            Bundle bundle = new Bundle();
                            bundle.putString("id", advertiseBean.getLinkId());
                            RouterManager.router(ARouterPathConstant.NEWS_CATCH, bundle);
                        }
                        break;
                        default:
                            break;
                    }
                    break;
                case "4": {
                    Bundle bundle = new Bundle();
                    bundle.putString("actId", advertiseBean.getLinkId());
                    RouterManager.router(ARouterPathConstant.ACT_DETAILS, bundle);
                    ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.ACTIVITY_DETAIL);
                }
                break;
                case "5": {
                    Bundle bundle = new Bundle();
                    String userName = CommonUtils.getInstance().getUserName();
                    bundle.putString("userName", userName);
                    bundle.putInt("id", Integer.parseInt(advertiseBean.getLinkId()));
                    RouterManager.routerLoginInterceptor(getContext(), bundle, ARouterPathConstant.NINE_LUCK_DRAW);
                    ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.LOTTERY);
                }
                break;
                default:
                    break;

            }
        } else {
            Bundle bundle = new Bundle();
            bundle.putString("title", advertiseBean.getTitle());
            bundle.putString("id", advertiseBean.getId() + "");
            bundle.putString("url", advertiseBean.getLink());
            bundle.putBoolean("hasJS", true);
            if (advertiseBean.getIsShare() != null && "0".equals(advertiseBean.getIsShare())) {
                bundle.putBoolean("hasShare", false);
            }
            RouterManager.router(ARouterPathConstant.ADV, bundle);
        }
        ActionLogUtils.getInstance().onEvent(ActionConstant.FLOWSCENE, ActionConstant.HOME, ActionConstant.ADV);
    }

    private List<GlobalNewsBean> dataTranslate(List<GatherBean> beanList) {
        List<GlobalNewsBean> indexList = new ArrayList<>();
        //转换数据模型
        for (int i = 0; i < beanList.size(); i++) {
            switch (beanList.get(i).getType()) {
                case "1"://置顶新闻
                    HomeBean.TopNews bean1 = beanList.get(i).getTop();
                    String type1 = "";
                    int newsStyle = 1;
                    switch (bean1.getType()) {
                        case "0":
                            type1 = "0";
                            break;
                        case "1"://普通新闻
                            type1 = "1";
                            break;
                        case "2"://图片新闻
                            type1 = "2";
                            break;
                        case "3"://直播
                            type1 = "9";
                            break;
                        case "4"://标题新闻
                            type1 = "8";
                            break;
                        case "5"://视频新闻
                            type1 = "3";
                            break;
                        case "8"://互动直播
                            bean1.setArticleID(bean1.getRoomId());//将roomId设置成通用Id
                            type1 = "5";
                            break;
                        case "101"://抓取新闻
                            type1 = "10";
                            break;
                        case "102"://小视频
                            type1 = "7";
                            break;
                        case "JLCommonNews":
                            newsStyle = 1;
                            type1 = "13";
                            break;
                        case "JLVideoNews":
                            newsStyle = 2;
                            type1 = "13";
                            break;
                        case "JLOutNews":
                            newsStyle = 3;
                            type1 = "13";
                            break;
                        default:
                            break;
                    }
                    if ("0".equals(type1)) {
                        if ("1".equals(bean1.getActivityJson().getType())) {
                            type1 = "11";//投票活动
                        } else {
                            type1 = "12";
                        }
                    }
                    //是否是无图
                    boolean hasPicture = StringUtils.isPictureSuccess(bean1.getArticleImg());
                    indexList.add(new GlobalNewsBean(bean1.getArticleTitle(), bean1.getArticleID(), bean1.getArticleURL(), bean1.getArticleImg(), newsStyle, null, "0", 0, null, bean1.getCatalogID(), hasPicture, type1, bean1.getLivetype()));
                    break;
                case "2"://新闻类型
                    NewsBean bean2 = beanList.get(i).getNews();
                    hasPicture = StringUtils.isPictureSuccess(bean2.getLogo());
                    String type = "", pOne = "", pTwo = "", pThree = "";
                    int style = 0;
                    switch (StringUtils.isEmpty(bean2.getType()) ? "10000" : bean2.getType()) {
                        case "1"://普通新闻
                            type = "1";
                            switch (bean2.getPluralPicsFlag()) {
                                case 0:
                                    style = bean2.getCommonStyle();
                                    break;
                                case 1://三图
                                    hasPicture = false;
                                    if (bean2.getImagess().size() == 1) {
                                        hasPicture = true;
                                        pOne = bean2.getImagess().get(0).getImageUrlString();
                                    } else if (bean2.getImagess().size() == 2) {
                                        pOne = bean2.getImagess().get(0).getImageUrlString();
                                        pTwo = bean2.getImagess().get(1).getImageUrlString();
                                        hasPicture = true;
                                    } else if (bean2.getImagess().size() >= 3) {
                                        pOne = bean2.getImagess().get(0).getImageUrlString();
                                        pTwo = bean2.getImagess().get(1).getImageUrlString();
                                        pThree = bean2.getImagess().get(2).getImageUrlString();
                                        hasPicture = true;
                                    } else {
                                        hasPicture = false;
                                    }
                                    style = 4;
                                    break;
                                case 2:
                                    style = 3;
                                    break;
                                default:
                                    style = bean2.getCommonStyle();
                                    break;
                            }
                            break;
                        case "2"://图片新闻
                            type = "2";
                            if (bean2.getImagess() == null || bean2.getImagess().size() < 1) {
                                continue;
                            }
                            if (bean2.getImagess().size() == 1) {
                                hasPicture = true;
                                pOne = bean2.getImagess().get(0).getImageUrlString();
                            } else if (bean2.getImagess().size() == 2) {
                                pOne = bean2.getImagess().get(0).getImageUrlString();
                                pTwo = bean2.getImagess().get(1).getImageUrlString();
                                hasPicture = true;
                            } else if (bean2.getImagess().size() >= 3) {
                                pOne = bean2.getImagess().get(0).getImageUrlString();
                                pTwo = bean2.getImagess().get(1).getImageUrlString();
                                pThree = bean2.getImagess().get(2).getImageUrlString();
                                hasPicture = true;
                            } else {
                                hasPicture = false;
                            }
                            break;
                        case "3"://直播
                            type = "9";
                            break;
                        case "4"://标题新闻
                            type = "8";
                            break;
                        case "5"://视频新闻
                            type = "3";
                            style = bean2.getVideoStyle();
                            break;
                        case "8"://互动直播
                            type = "5";
                            bean2.setID(bean2.getRoomId());//将roomId设置成通用Id
                            break;
                        case "101"://抓取新闻
                            type = "10";
                            break;
                        default:
                            break;
                    }
                    indexList.add(new GlobalNewsBean(bean2.getTitle(), bean2.getID(), bean2.getRedirectURL(), bean2.getLogo(), style, bean2.getPublishDate(), type, Integer.parseInt(bean2.getHitCount()), bean2.getSource(), bean2.getCatalogID(), hasPicture, pOne, pTwo, pThree, bean2.getLivetype(), bean2.getCommentCount()));
                    break;
                case "3"://小视频
                    NewsBean bean3 = beanList.get(i).getNews();
                    if (bean3 != null) {
                        indexList.add(new GlobalNewsBean(bean3.getTitle(), bean3.getID(), bean3.getLink(), bean3.getLogo(), 0, bean3.getPublishDate(), "7", bean3.getCommentCount(), bean3.getSource(), bean3.getCatalogID(), true, bean3.getLivetype()));
                    }
                    break;
                case "4"://新趣汇
                    NewsBean bean4 = beanList.get(i).getNews();
                    if (bean4 != null) {
                        indexList.add(new GlobalNewsBean(bean4.getTitle(), bean4.getID(), bean4.getRedirectURL(), bean4.getLogo(), 0, bean4.getPublishDate(), "6", Integer.parseInt(StringUtils.isNotEmpty(bean4.getHitCount()) ? bean4.getHitCount() : "0"), bean4.getSource(), bean4.getCatalogID(), true, bean4.getLivetype()));
                    }
                    break;
                case "5"://广告类型
                    AdvertiseBean bean = beanList.get(i).getAdv();
                    if (bean != null) {
                        GlobalNewsBean data = new GlobalNewsBean(bean.getTitle(), bean.getId() + "", bean.getLink(), bean.getImageUrl(), Integer.parseInt(bean.getStyle()), bean.getCatalogID(), "4", 0, bean.getContentType(), bean.getLinkId(), true, bean.getLinkType());
                        data.setIsShare(bean.getIsShare());
                        indexList.add(data);
                    }
                    break;
                case "6"://乡镇
                    UnionBean unionBean = beanList.get(i).getCatalog();
                    if (unionBean != null) {
                        indexList.add(new GlobalNewsBean(unionBean.getName(), unionBean.getInnercode() + "", "", unionBean.getLogo(), beanList.get(i).getPrejectStyle(), null, "11", 0, null, unionBean.getId(), true, null));
                    }
                    break;
                case "7"://政务
                    UnionBean unionBean1 = beanList.get(i).getCatalog();
                    if (unionBean1 != null) {
                        indexList.add(new GlobalNewsBean(unionBean1.getName(), unionBean1.getInnercode() + "", "", unionBean1.getLogo(), beanList.get(i).getPrejectStyle(), null, "12", 0, null, unionBean1.getId(), true, null));
                    }
                    break;
                case "8"://专题
                    UnionBean unionBean2 = beanList.get(i).getCatalog();
                    if (unionBean2 != null) {
                        indexList.add(new GlobalNewsBean(unionBean2.getName(), unionBean2.getInnercode() + "", "", unionBean2.getLogo(), beanList.get(i).getPrejectStyle(), null, "13", 0, null, unionBean2.getId(), true, null));
                    }
                    break;
                case "9"://图文直播
                    TeleTextBean teleTextBean = beanList.get(i).getLiveNews();
                    if (teleTextBean != null) {
                        indexList.add(new GlobalNewsBean(teleTextBean.getTitle(), teleTextBean.getId() + "", teleTextBean.getType(), teleTextBean.getCoverPic(), 0, teleTextBean.getCreatetime(), "14", Integer.parseInt(teleTextBean.getHits()), teleTextBean.getStatus(), teleTextBean.getChatroomId(), true, null));
                    }
                    break;
                case "10"://圈子
                    CircleHomeBean circleHomeBean = beanList.get(i).getTopicInfo();
                    int pictureNum = 0;
                    String picOne = "", picTwo = "", picThree = "";
                    hasPicture = false;
                    if (circleHomeBean != null) {
                        String topicName = null;
                        if (circleHomeBean.getTagList() != null && circleHomeBean.getTagList().size() > 0) {
                            topicName = circleHomeBean.getTagList().get(0).getName();
                        } else {
                            topicName = "";
                        }
                        if (circleHomeBean.getPicList() != null && circleHomeBean.getPicList().size() > 0) {
                            hasPicture = true;
                            if (circleHomeBean.getPicList().size() == 1) {
                                pictureNum = 1;
                                picOne = circleHomeBean.getPicList().get(0).getThumb();
                            } else if (circleHomeBean.getPicList().size() == 2) {
                                pictureNum = 2;
                                picOne = circleHomeBean.getPicList().get(0).getThumb();
                                picTwo = circleHomeBean.getPicList().get(1).getThumb();
                            } else if (circleHomeBean.getPicList().size() == 3) {
                                pictureNum = 3;
                                picOne = circleHomeBean.getPicList().get(0).getThumb();
                                picTwo = circleHomeBean.getPicList().get(1).getThumb();
                                picThree = circleHomeBean.getPicList().get(2).getThumb();
                            } else {
                                picOne = circleHomeBean.getPicList().get(0).getThumb();
                                picTwo = circleHomeBean.getPicList().get(1).getThumb();
                                picThree = circleHomeBean.getPicList().get(2).getThumb();
                                pictureNum = circleHomeBean.getPicList().size();
                            }
                        }
                        indexList.add(new GlobalNewsBean(circleHomeBean.getContent(), circleHomeBean.getId() + "", circleHomeBean.getVideo(), circleHomeBean.getVideoThumb(), "", circleHomeBean.getType()
                                , circleHomeBean.getGmtCreate(), "15", circleHomeBean.getPageview(), topicName, circleHomeBean.getUser().getNickName(), hasPicture, "", picOne, picTwo, picThree, pictureNum));
                    }
                    break;
                case "11"://圈子话题
                    CircleHomeBean.TagList circleTag = beanList.get(i).getCircleTag();
                    if (circleTag != null) {
                        indexList.add(new GlobalNewsBean(circleTag.getName(), circleTag.getId() + "", "", circleTag.getPic(), 0,
                                "", "16", 0, circleTag.getDesc(), "", true, ""));
                    }
                    break;
                case "12"://报料栏目
                    ScoopTopicBean scoopTopicBean = beanList.get(i).getBrokeNewsPlate();
                    if (scoopTopicBean != null) {
                        indexList.add(new GlobalNewsBean(scoopTopicBean.getName(), scoopTopicBean.getId() + "", "", "", 0, "",
                                "17", 0, "", "", false, ""));
                    }
                    break;
                case "13"://报料
                    ScoopListBean scoopListBean = beanList.get(i).getBrokeNews();
                    hasPicture = false;
                    String one = "", two = "", three = "";
                    int picNum = 0;
                    if (scoopListBean != null) {
                        if (scoopListBean.getImages() != null && scoopListBean.getImages().size() > 0) {
                            hasPicture = true;
                            if (scoopListBean.getImages().size() == 1) {
                                one = scoopListBean.getImages().get(0).getThumbnailUrl();
                            } else if (scoopListBean.getImages().size() == 2) {
                                one = scoopListBean.getImages().get(0).getThumbnailUrl();
                                two = scoopListBean.getImages().get(1).getThumbnailUrl();
                            } else if (scoopListBean.getImages().size() == 3) {
                                one = scoopListBean.getImages().get(0).getThumbnailUrl();
                                two = scoopListBean.getImages().get(1).getThumbnailUrl();
                                three = scoopListBean.getImages().get(2).getThumbnailUrl();
                            } else {
                                one = scoopListBean.getImages().get(0).getThumbnailUrl();
                                two = scoopListBean.getImages().get(1).getThumbnailUrl();
                                three = scoopListBean.getImages().get(2).getThumbnailUrl();
                                picNum = scoopListBean.getImages().size();
                            }
                        }
                        indexList.add(new GlobalNewsBean(scoopListBean.getBrokeNews().getTitle(), scoopListBean.getBrokeNews().getId() + "", scoopListBean.getBrokeNews().getUrl()
                                , scoopListBean.getBrokeNews().getCoverImgUrl(), scoopListBean.getBrokeNews().getStatus() + "", scoopListBean.getBrokeNews().getType(), scoopListBean.getBrokeNews().getCreatetime(), "18"
                                , scoopListBean.getBrokeNews().getClickAmount(), scoopListBean.getBrokePlate() != null ? scoopListBean.getBrokePlate().getName() : "", scoopListBean.getBrokeNews().getContent(), hasPicture, "", one, two, three, picNum));
                    }
                    break;
                case "14"://新活动
                    ActDetailsBean actDetailsBean = beanList.get(i).getActivity();
                    int personNum;
                    try {
                        personNum = actDetailsBean.getActivity().getActivity().getPageViews().intValue();
                    } catch (Exception e) {
                        personNum = 0;
                    }
                    if (actDetailsBean != null) {
                        indexList.add(new GlobalNewsBean(actDetailsBean.getActivity().getActivity().getActName(), actDetailsBean.getActivity().getActivity().getId() + "", "", actDetailsBean.getActivity().getActivity().getPosterUrl(),
                                0, actDetailsBean.getActivity().getActivity().getCreateTime(), "19", personNum, "", actDetailsBean.getActivity().getActivity().getDigest(), true, "19"));
                    }
                    break;
                default:
                    break;
            }
        }
        return indexList;
    }
}
